package com.xinsoft.controller.basic;


import com.xinsoft.aop.ano.SysLog;
import com.xinsoft.common.BusinessType;
import com.xinsoft.common.Response;
import com.xinsoft.entity.po.SysDictionary;
import com.xinsoft.service.SysDictionaryService;
import com.xinsoft.validator.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName SysDictController
 * @Description 字典项控制层
 * @Author lijie
 * @Date 2023年5月16日17:14:04
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/dict")
@Api(value = "SysDictController", tags = {"字典项控制层"})
public class SysDictController {

    @Autowired
    private SysDictionaryService dictionaryService;

   /**
    * @Author Li9527
    * @Description 新增
    * @Date 2023/5/11 17:08
    * @params   sysCompanyDTO
    * @return com.xinsoft.common.Response<?>
    **/
   @SysLog(title = "字典项-新增", businessType = BusinessType.INSERT)
   @ApiOperation("新增")
   @PostMapping("/add")
    public Response<?> add(@RequestBody SysDictionary dictionary) {
        // 参数校验
       ValidatorUtils.validateEntity(dictionary);
       return Response.succeed(dictionaryService.save(dictionary));
    }

    /**
     * @Author Li9527
     * @Description 更新
     * @Date 2023/5/12 9:19
     * @params   sysCompany
     * @return com.xinsoft.common.Response<?>
     **/
    @ApiOperation("更新")
    @SysLog(title = "字典项-编辑", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Response<?> edit(@RequestBody SysDictionary dictionary) {
        // 参数校验
        ValidatorUtils.validateEntity(dictionary);
        return Response.succeed(dictionaryService.updateById(dictionary));
    }

    /**
     * @Author Li9527
     * @Description 获取详情
     * @Date 2023/5/12 9:20
     * @params   id
     * @return com.xinsoft.common.Response<?>
     **/
    @ApiOperation("获取详情")
    @GetMapping("/detail")
    public Response<?> detail(@RequestParam(value = "id", defaultValue = "", required = true) Integer id) {
        return Response.succeed(dictionaryService.getById(id));
    }

    /**
     * @Author Li9527
     * @Description 删除
     * @Date 2023/5/12 9:20
     * @params   ids
     * @return com.xinsoft.common.Response<?>
     **/
    @ApiOperation("删除")
    @SysLog(title = "字典项-删除", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public Response<?> del(@RequestBody List<Integer> ids) {
        dictionaryService.removeByIds(ids);
        return Response.succeed();
    }

}
